<template>
  <div class="login_panel">
    <h1 class="title">
      <slot />
    </h1>

    <div class="tabs">
      <el-tabs type="border-card" :stretch="true" v-model="activeName">
        <el-tab-pane name="account">
          <template #label>
            <div class="tab-pance">
              <el-icon><UserFilled /></el-icon>
              <span class="tab-pance-text">账号登录</span>
            </div>
          </template>
          <panceAccount ref="AccountRef" />
        </el-tab-pane>
      </el-tabs>
    </div>

    <div class="controls">
      <el-checkbox v-model="isRememberPwd" label="记住账号和密码" size="large" />
      <el-link type="primary">忘记密码</el-link>
    </div>

    <el-button type="primary" size="large" class="login-btn" @click="loginBtn">立即登录</el-button>
  </div>
</template>

<script setup lang="ts">
import { ref, watch, watchEffect } from 'vue'

import panceAccount from './panceAccount.vue'

import { localCache } from '@/utils/cache'
// eslint-disable-next-line

const activeName = ref<string>('account')
const isRememberPwd = ref<boolean>(localCache.getCache('isRemember') ?? false)

watch(isRememberPwd, (newvalue) => {
  console.log(newvalue)
  localStorage.setItem('isRemember', JSON.stringify(newvalue))
})

const AccountRef = ref<InstanceType<typeof panceAccount>>()

const loginBtn = () => {
  if (activeName.value === 'account') {
    AccountRef.value?.loginAction(isRememberPwd.value)
    return
  }
}
</script>

<style lang="scss" scoped>
.login_panel {
  width: 20.625em;
  margin-bottom: 9.375em;
  .title {
    text-align: center;
    margin-bottom: 1em;
  }
  .controls {
    margin-top: 0.7em;
    display: flex;
    justify-content: space-between;
  }
  .login-btn {
    width: 100%;
    margin-top: 0.7em;
  }
  .tab-pance {
    display: flex;
    justify-content: center;
    align-items: center;
    .tab-pance-text {
      margin-left: 0.3em;
    }
  }
}
</style>
